//
//  RecommendedController.m
//  Otaku
//
//  Created by lanou3g on 16/5/5.
//  Copyright © 2016年 Liuwx. All rights reserved.
//

#import "RecommendedController.h"
#import "Parameter.h"
#import "LWXPagerView.h"
#import "AgreementController.h"
#import "RecommendedViewController.h"
#import "VideoViewController.h"
#import "PictureViewController.h"
#import "JokesViewController.h"
#import "EssenceViewController.h"
#import "SameCityViewController.h"
#import "LoginViewController.h"

@interface RecommendedController ()<LWXPagerViewDelegate>
//@property (nonatomic, strong) NSArray *array;
@end

@implementation RecommendedController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor grayColor];
    UIImage *backImage = [UIImage imageNamed:@"head_bg.png"];
    self.title = @"首页";
    
   // self.array = @[@"精选",@"关注"];
    
    [self.navigationController.navigationBar setBackgroundImage:backImage forBarMetrics:UIBarMetricsDefault];
//    UISegmentedControl *segmentedC = [[UISegmentedControl alloc]initWithItems:self.array];
//    [segmentedC addTarget:self action:@selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];
//    
//    self.navigationItem.titleView = segmentedC;
    

    
    
    // 设置头像
    UIImage *loginImage = [UIImage imageNamed:@"big_defaulthead_head.png"];
// 还原头像
    UIImage *newLoginImage = [loginImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 设置自定义 item
    UIButton *loginBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
    // 切圆
    loginBtn.layer.cornerRadius = 22;
    loginBtn.layer.masksToBounds = YES;
    [loginBtn setImage:newLoginImage forState:(UIControlStateNormal)];
    [loginBtn addTarget:self action:@selector(LoginAction:) forControlEvents:(UIControlEventTouchUpInside)];

    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:loginBtn];
    UIImage *agreementImage = [UIImage imageNamed:@"submission.png"];
    UIImage *newAgreementImage = [agreementImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:newAgreementImage style:(UIBarButtonItemStylePlain) target:self action:@selector(agreementAction:)];
    
    self.navigationItem.rightBarButtonItem = item;
    
    
    self.navigationController.navigationBar.translucent = NO;
    NSArray *titleArray = @[@"推荐",
                            @"视频",
                            @"图片",
                            @"段子",
                            @"精华",
                            @"同城"];
    RecommendedViewController *recommendedC = [[RecommendedViewController alloc]init];
    VideoViewController *videoC = [[VideoViewController alloc]init];
    PictureViewController *pictureC = [[PictureViewController alloc] init];
    JokesViewController *jokesC = [[JokesViewController alloc]init];
    EssenceViewController *essenceC = [[EssenceViewController alloc] init];
    SameCityViewController *sameCityC = [[SameCityViewController alloc]init];
    
    NSArray *detailVCsArray = @[recommendedC,videoC,pictureC,jokesC,essenceC,sameCityC];
    NSArray *colorArray = @[[UIColor brownColor],[UIColor grayColor],[UIColor redColor],[UIColor whiteColor]];
    LWXPagerView *lwxPagerView = [[LWXPagerView alloc] initWithTitles:titleArray WithVCs:detailVCsArray WithColorArrays:colorArray];
    lwxPagerView.delegate = self;
    [self.view addSubview:lwxPagerView];
    
    lwxPagerView.pushEnabled = YES;
    // Do any additional setup after loading the view.
}

//- (void)segmentedAction:(UISegmentedControl *)segment {
//    switch (segment.selectedSegmentIndex) {
//        case 0: {
//        /// 精选
//           
//            
//            
//        }
//            break;
//            
//        case 1: {
//        /// 关注
//           
//            
//            
//        }
//            break;
//  
//        default:
//            break;
//    }
//}

// 点击登录进入登录页面
- (void)LoginAction:(UIButton *)btn {
    
    LoginViewController *loginVC = [[LoginViewController alloc]init];
    UINavigationController *naVC = [[UINavigationController alloc]initWithRootViewController:loginVC];
    [self presentViewController:naVC animated:YES completion:nil];
    
    
    
}

// 协议点击事件
- (void)agreementAction:(UIButton *)btn {
    AgreementController *agreementVC = [[AgreementController alloc]init];
    UINavigationController *naVC = [[UINavigationController alloc]initWithRootViewController:agreementVC];

    [self presentViewController:naVC animated:YES completion:nil];
    
    
    
    
    
    
}

- (BOOL)deallocVCsIfUnnecessary {
    return YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
